def triangle_wave(x, c, c0, hc):
    x = x - int(x)
    if x >= c: r = 0.0
    elif x < c0: r = x / c0 * hc
    else: r = (c - x) / (c - c0) * hc
    return r

